package com.blb.mapper;

import com.blb.entity.Classification;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.entity.Notes;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yanghao
 * @since 2019-12-21
 */
public interface ClassificationMapper extends BaseMapper<Classification> {
    List<Classification> getAllClassification(String pid,String recycle,String userId);

    @Select("select * from t_classification where pid=#{id} and recycle=#{recycle}")
    List<Classification> getFolderByPid(String id,String recycle);

    @Select("select * from t_notes where classification_id=#{classificationId}")
    List<Notes> getNoteByClassificationId(String classificationId);

    @Update("update t_classification set pid=#{pid} where id=#{id}")
    void updateMoveFolder(Classification classification);

    @Update("update t_classification set menuname=#{menuname} where id=#{id}")
    void updateFolderName(Classification classification);
    @Update("update t_classification set recycle=#{recycle} where id=#{id}")
    void updateRecycleById(String recycle,String id);
    /**
     * 根据pid查询层级文件夹
     * @param pid
     * @return
     */
    @Select("SELECT * FROM t_classification WHERE pid =#{pid} and user_id=#{userId} and recycle=#{recycle}")
    List<Classification> getAllFolder(String pid,String userId,String recycle);

    /**
     * 根据没有父级查找所有笔记
     * @return
     */
    @Select("SELECT * FROM t_notes WHERE classification_id is NULL and user_id=#{userId} and recycle=#{recycle}")
    List<Notes> getAllNotes(String userId,String recycle);

    /**
     * 根据id查询笔记
     * @param id
     * @return
     */
    @Select("SELECT * FROM `t_notes` WHERE id=#{id}")
    Notes getNoteById(String id);

    /**
     * 根据classification_id查询所有笔记
     * @return
     */
    @Select("SELECT * FROM t_notes WHERE classification_id=#{classificationId} and user_id=#{userId} and recycle=#{recycle}")
    List<Notes> getAllNotesByClassId(String classificationId,String userId,String recycle);

}
